home *** CD-ROM | disk | FTP | other *** search
/ CD ROM Paradise Collection 4 / CD ROM Paradise Collection 4 1995 Nov.iso / database / bltc121.zip / BC_LAI10.C < prev    next >
C/C++ Source or Header  |  1995-01-05  |  7KB  |  249 lines

  1.         
  2. #include <stdio.h>
  3. #include <stdlib.h>
  4. #include <time.h>
  5. #include <string.h>
  6.  
  7. #include "bullet.h"
  8.  
  9. #pragma pack(1)
  10.             
  11. /* --test raw speed using 32-bit long integer key, unique
  12.    1) this test uses a non-standard binary field as a sort field
  13.    2) this code is for raw speed tests--it's straight inline
  14.  
  15.  To compile, just set you compiler to large memory model, have it
  16.  link in BULLET.LIB, and that's it.  Borland compilers use BULLET_L.LIB.
  17.  
  18. */
  19.  
  20. struct MemoryPack MP;
  21. struct InitPack IP;
  22. struct ExitPack EP;
  23. struct FieldDescType fieldList[2];
  24. struct CreateDataPack CDP;
  25. struct CreateKeyPack CKP;
  26. struct DosFilePack DFP;
  27. struct OpenPack OP;
  28. struct AccessPack AP;
  29. struct ExitPack EP;
  30.  
  31. int    rez, level;
  32. div_t    div_rez;
  33. time_t  startTime, endTime;
  34.  
  35. char    tmpStr[129];
  36.  
  37. char    nameDat[] = ".\\BINTEST.DBB";
  38. char    nameIx1[] = ".\\BINTEST.IX1";
  39.  
  40. char    kx1[] = "CODENUMBER";
  41.  
  42. unsigned handDat, handIx1;
  43.  
  44. struct TestRecType {
  45.  char  tag;
  46.  long  codeNumber;
  47.  char  codeName[11];
  48. }; /* test program record length=16 bytes */
  49. struct TestRecType testRec;
  50.  
  51. char    keyBuffer[64]; /* MUST supply a work buffer for keys */
  52.                        /* a single one can be shared unless you */
  53.                        /* want to preserve the key buffer for each */
  54.                        /* access pack.  You read a gotten key from */
  55.                        /* here, and also specify key to find here */
  56.                        /* READ THE DOCS on exact matches, et al., */
  57.                        /* especially about "enumerator word", partial */
  58.                        /* match (follow with GetNext/Prev), and so on */
  59.  
  60. long    recs2add;
  61. long    low;
  62. long    high;
  63. long    i;
  64.  
  65. #pragma pack()
  66.  
  67. int main()
  68. {
  69.  
  70. /* implicit is the tag field at the first byte, then comes... */
  71. strcpy(fieldList[0].fieldName, "CODENUMBER");
  72. fieldList[0].fieldType = 'B';
  73. fieldList[0].fieldLen = 4;
  74. fieldList[0].fieldDC = 0;
  75. strcpy(fieldList[1].fieldName, "CODENAME\0\0");  /* must be 0-filled */
  76. fieldList[1].fieldType = 'C';
  77. fieldList[1].fieldLen = 11;   /* 10 and 1 for eos */
  78. fieldList[1].fieldDC = 0;
  79.  
  80. puts("BC_LAI10.C - LONG INT, SIGNED, UNIQUE long int, add/reindex speed test");
  81. puts("-Uses non-standard data files with binary field values, not DBF (in this test)");
  82. puts("-If TMP= defined in environment, reindex routine uses that path for temporary");
  83. puts("workspace, otherwise the current directory is used.\n");
  84.  
  85. level = 100;
  86. MP.func = MEMORYXB;
  87. rez = BULLET(&MP);   /* not really significant */
  88. printf("memory avail   : %lu\n",MP.memory);
  89. if (MP.memory < 40000l) {
  90.    rez = 8;
  91.    goto Abend;
  92. }
  93.  
  94. level = 110;
  95. IP.func = INITXB;
  96. IP.JFTmode = 0;
  97. rez = BULLET(&IP);
  98. if (rez != 0) goto Abend;
  99.  
  100. level = 120;
  101. EP.func = ATEXITXB;
  102. rez = BULLET(&EP);
  103. if (rez != 0) goto Abend;    /* actually, not a fatal error */
  104.  
  105. level = 130;                         /* disregard not found errors */
  106. DFP.func = DELETEFILEDOS;
  107. DFP.filenamePtr = nameDat;
  108. rez = BULLET(&DFP);
  109. DFP.filenamePtr = nameIx1;
  110. rez = BULLET(&DFP);
  111.  
  112. level = 1000;
  113. CDP.func = CREATEDXB;
  114. CDP.filenamePtr = nameDat;
  115. CDP.noFields = 2;
  116. CDP.fieldListPtr = fieldList;
  117. CDP.fileID = 255;
  118. rez = BULLET(&CDP);
  119. if (rez !=0) goto Abend;
  120.  
  121. level = 1010;
  122. OP.func = OPENDXB;
  123. OP.filenamePtr = nameDat;
  124. OP.asMode = READWRITE | DENYNONE;
  125. rez = BULLET(&OP);
  126. if (rez !=0) goto Abend;
  127. handDat = OP.handle;
  128.  
  129. level = 1100;
  130. CKP.func = CREATEKXB;
  131. CKP.filenamePtr = nameIx1;
  132. CKP.keyExpPtr = kx1;
  133. CKP.xbLink = handDat;
  134. CKP.keyFlags = cLONG | cSIGNED | cUNIQUE;
  135. CKP.codePageID = -1;
  136. CKP.countryCode = -1;
  137. CKP.collatePtr = NULL;
  138. rez = BULLET(&CKP);
  139. if (rez !=0) goto Abend;
  140.  
  141. level = 1110;
  142. OP.func = OPENKXB;
  143. OP.filenamePtr = nameIx1;
  144. OP.asMode = READWRITE | DENYNONE;
  145. OP.xbLink = handDat;
  146. rez = BULLET(&OP);
  147. if (rez !=0) goto Abend;
  148. handIx1 = OP.handle;
  149.  
  150. AP.func = ADDRECORDXB;
  151. AP.handle = handDat;
  152. AP.recPtr = &testRec;
  153. AP.keyPtr = keyBuffer;       /* set here and used throughout  */
  154. AP.nextPtr = NULL;
  155.  
  156. testRec.tag = ' ';
  157. strcpy(testRec.codeName, "xxSAME-Oxx");
  158.  
  159. printf("Recs to add/reindex: ");
  160. gets(tmpStr);
  161. recs2add = atol(tmpStr);
  162. if (recs2add == 0L) recs2add = 5L;
  163.  
  164. level = 1200;
  165. low = -3L;
  166. high = low + recs2add - 1L;
  167. printf("Adding %ld records ( keys %ld to %ld )...\n",recs2add,low,high);
  168.  
  169. time(&startTime);
  170. for (i = low; i < (recs2add+low); i++) {
  171.    testRec.codeNumber = i;
  172.    rez = BULLET(&AP);
  173.    if (rez !=0) goto Abend;
  174. }
  175. time(&endTime);
  176. printf("...took %lu secs.\n",(endTime - startTime));
  177.  
  178. level = 1210;
  179. printf("Reindexing...\n");
  180. AP.func = REINDEXXB;
  181. AP.handle = handIx1;
  182. time(&startTime);
  183. rez = BULLET(&AP);
  184. time(&endTime);
  185. if (rez != 0) {
  186.    rez = AP.stat;    /* MUST take AP.stat since a xaction routine */
  187.    goto Abend;       /* see docs and !README2.TXT for more */
  188. }
  189. printf("...took %lu secs\n\n",(endTime - startTime));
  190.  
  191. level = 1300;
  192. AP.func = GETFIRSTXB;
  193. rez = BULLET(&AP);
  194. printf("  The first 5 key/recs  (recNo --- key - data)\n");
  195. printf("%7lu %7ld %.10s\n",AP.recNo,testRec.codeNumber,testRec.codeName);
  196. for (i=1;i < 5; i++) {
  197.    if (rez != 0) break;
  198.    AP.func = GETNEXTXB;
  199.    rez = BULLET(&AP);
  200.    printf("%7lu %7ld %.10s\n",AP.recNo,testRec.codeNumber,testRec.codeName);
  201. }
  202. if (rez == 202) rez = 0;
  203. if (rez != 0) goto Abend;
  204. puts(" ");
  205.  
  206. level = 1310;
  207. AP.func = GETLASTXB;
  208. rez = BULLET(&AP);
  209. printf("  The last 5 key/recs\n");
  210. printf("%7lu %7ld %.10s\n",AP.recNo,testRec.codeNumber,testRec.codeName);
  211. for (i=1;i < 5; i++) {
  212.    if (rez != 0) break;
  213.    AP.func = GETPREVXB;
  214.    rez = BULLET(&AP);
  215.    printf("%7lu %7ld %.10s\n",AP.recNo,testRec.codeNumber,testRec.codeName);
  216. }
  217. if (rez == 203) rez = 0;
  218. if (rez != 0) goto Abend;
  219.  
  220. level = 1311;
  221. printf("  Finding the last gotten key, (in AP.keybuffer already)\n");
  222. AP.func = GETEQUALXB;
  223. rez = BULLET(&AP);
  224. printf("%7lu %7ld %.10s\n",AP.recNo,testRec.codeNumber,testRec.codeName);
  225. if (rez != 0) goto Abend;
  226.  
  227. level = 1312;
  228. printf("  Finding key of 5\n");
  229. AP.func = GETEQUALXB;
  230. *((long *)keyBuffer) = 5L;
  231. rez = BULLET(&AP);
  232. printf("%7lu %7ld %.10s\n",AP.recNo,testRec.codeNumber,testRec.codeName);
  233. if (rez != 0) goto Abend;
  234.  
  235. puts("Okay.");
  236. EP.func = EXITXB;
  237. rez = BULLET(&EP);
  238. return(0);
  239. /* program exit */
  240.  
  241.  
  242. /*----------------------------------------------*/
  243. /* that's right, we go to a termination routine */
  244.  
  245. Abend:
  246.    printf("Error: %u at level %u while performing ",rez,level);
  247.    exit(1);
  248. }
  249.